<template>
  <div :style="{ ...coreStyle.marginSame(8) }">
    <a-card>
      <a-form ref="taskExpressionFormQueryRef" :model="taskExpressionFormQueryModel" labelAlign="left" layout="vertical" :style="{ ...coreStyle.marginBottom(10) }">
        <a-row :gutter="16" v-show="!taskExpressionFormQueryVisible">
          <a-col :span="8">
            <a-form-item :style="{ ...coreStyle.marginBottom(-8) }">
              <a-input-search v-model:value="taskExpressionFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="taskExpressionFormQuerySubmitting" @search="taskExpressionFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
            <a-button type="link" :style="{ ...coreStyle.floatRight }" @click="taskExpressionFormQueryUpDown">
              展开
              <CoreIcon :icon="coreStyle.antBtnIconExpand" :size="14" />
            </a-button>
          </a-col>
        </a-row>
        <a-row :gutter="16" v-show="taskExpressionFormQueryVisible">
          <a-col :span="8">
            <a-form-item>
              <a-input-search v-model:value="taskExpressionFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="taskExpressionFormQuerySubmitting" @search="taskExpressionFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
          </a-col>
          <a-col :span="8">
            <a-form-item label="计算公式Id">
              <a-input v-model:value="taskExpressionFormQueryModel.expressionIdAndLike" placeholder="输入计算公式Id" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="描述">
              <a-input v-model:value="taskExpressionFormQueryModel.descriptionAndLike" placeholder="输入描述" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="排序权重">
              <a-input-number v-model:value="taskExpressionFormQueryModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="外键Id">
              <a-input v-model:value="taskExpressionFormQueryModel.fkidAndLike" placeholder="输入外键Id" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-space :style="{ ...coreStyle.floatRight }">
              <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="taskExpressionFormQueryReset">
                <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
                重置
              </a-button>
              <a-button :loading="taskExpressionFormQuerySubmitting" type="dashed" :style="{ ...coreStyle.antBtnQuery }" @click="taskExpressionFormQuerySearch">
                <CoreIcon :icon="coreStyle.antBtnIconQuery" :size="14" />
                查询
              </a-button>
              <a-button type="dashed" ghost :style="{ ...coreStyle.antBtnRetract }" @click="taskExpressionFormQueryUpDown">
                收起
                <CoreIcon :icon="coreStyle.antBtnIconRetract" :size="14" />
              </a-button>
            </a-space>
          </a-col>
        </a-row>
      </a-form>
      <a-space>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnAdd }" @click="taskExpressionAdd">
          <CoreIcon :icon="coreStyle.antBtnIconAdd" :size="14" />
          新增
        </a-button>
        <a-button v-if="taskExpressionListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="taskExpressionUpdate">
          <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
          修改
        </a-button>
        <a-popconfirm v-if="taskExpressionListSelectLength > 0" title="确认删除？" okType="dashed" placement="bottom" @confirm="taskExpressionDelete">
          <a-button type="dashed" :style="{ ...coreStyle.antBtnDelete }">
            <CoreIcon :icon="coreStyle.antBtnIconDelete" :size="14" />
            删除
          </a-button>
        </a-popconfirm>
        <a-button v-if="taskExpressionListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnDetail }" @click="taskExpressionDetailInfo">
          <CoreIcon :icon="coreStyle.antBtnIconDetail" :size="14" />
          详情
        </a-button>
      </a-space>
      <a-space :style="{ ...coreStyle.floatRight }">
        <a-button type="dashed" :style="{ ...coreStyle.antBtnTemplateDownload }" @click="taskExpressionTemplateDownload">
          <CoreIcon :icon="coreStyle.antBtnIconTemplateDownload" :size="14" />
          模版下载
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnImport }" @click="taskExpressionDataImport">
          <CoreIcon :icon="coreStyle.antBtnIconImport" :size="14" />
          导入
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnExport }" @click="taskExpressionDataExport">
          <CoreIcon :icon="coreStyle.antBtnIconExport" :size="14" />
          导出
        </a-button>
        <a-button type="dashed" ghost shape="circle" :style="{ ...coreStyle.antBtnRefresh }" @click="taskExpressionListGetDataSet">
          <CoreIcon :icon="coreStyle.antBtnIconRefresh" :size="22" />
        </a-button>
      </a-space>
      <a-table
        rowKey="id"
        :columns="taskExpressionListColumns"
        :data-source="taskExpressionListDataSet"
        :loading="taskExpressionListLoading"
        :pagination="false"
        bordered
        :customRow="taskExpressionListCustomRow"
        :row-selection="{ fixed: true, selectedRowKeys: taskExpressionListSelectedRowKeys, onChange: taskExpressionListRowOnChange }"
        :scroll="{ x: '100%', y: 550 }"
        :style="{ ...coreStyle.marginTop(10) }"
      >
      </a-table>
      <a-pagination
        v-model:current="taskExpressionListDataPage"
        v-model:pageSize="taskExpressionListDataRows"
        :total="taskExpressionListDataCount"
        show-size-changer
        show-quick-jumper
        :page-size-options="[ ...coreStyle.antdPaginationPageSizeOptions ]"
        :show-total="(total, range) => coreStyle.antdPaginationShowTotal(total, range)"
        :style="{ ...coreStyle.marginTop(10), ...coreStyle.textAlignCenter }"
        @change="taskExpressionListPaginationChange"
        @showSizeChange="taskExpressionListPaginationShowSizeChange"
        v-if="taskExpressionListPaginationVisible"
      >
      </a-pagination>
      <p :style="{ ...coreStyle.marginTop(14), ...coreStyle.marginBottom(6), ...coreStyle.textAlignCenter }" v-if="!taskExpressionListPaginationVisible">
        {{ coreStyle.antdPaginationShowTotal(taskExpressionListDataCount) }}
      </p>
    </a-card>
    <a-drawer
      v-model:visible="taskExpressionEditDrawerVisible"
      title="编辑任务公式信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
      @close="taskExpressionEditDrawerOnClose"
    >
      <a-form ref="taskExpressionFormRef" :model="taskExpressionFormModel" :rules="taskExpressionFormRules" labelAlign="left" layout="vertical">
        <a-row :gutter="16">
          <a-col :span="12">
            <a-form-item label="计算公式Id" name="expressionId">
              <a-input v-model:value="taskExpressionFormModel.expressionId" placeholder="输入计算公式Id" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="描述" name="description">
              <a-input v-model:value="taskExpressionFormModel.description" placeholder="输入描述" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="排序权重" name="weightOrder">
              <a-input-number v-model:value="taskExpressionFormModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="外键Id" name="fkid">
              <a-input v-model:value="taskExpressionFormModel.fkid" placeholder="输入外键Id" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="taskExpressionFormReset">
            <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
            重置
          </a-button>
          <a-button :loading="taskExpressionFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnNextAdd }" @click="taskExpressionFormNextAdd">
            <CoreIcon :icon="coreStyle.antBtnIconNextAdd" :size="14" />
            继续录入
          </a-button>
          <a-button :loading="taskExpressionFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnSave }" @click="taskExpressionFormSave">
            <CoreIcon :icon="coreStyle.antBtnIconSave" :size="14" />
            保存
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="taskExpressionDetailDrawerVisible"
      title="任务公式详细信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
    >
      <a-space direction="vertical" :size="20" :style="{ ...coreStyle.width('100%') }">
        <a-descriptions title="基础信息" :column="2" bordered>
          <a-descriptions-item label="计算公式Id" :span="1">{{ taskExpressionDetailModel.expressionId }}</a-descriptions-item>
          <a-descriptions-item label="描述" :span="1">{{ taskExpressionDetailModel.description }}</a-descriptions-item>
          <a-descriptions-item label="排序权重" :span="1">{{ taskExpressionDetailModel.weightOrder }}</a-descriptions-item>
          <a-descriptions-item label="外键Id" :span="1">{{ taskExpressionDetailModel.fkid }}</a-descriptions-item>
        </a-descriptions>
      </a-space>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="taskExpressionDetailUpdate">
            <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
            修改
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="taskExpressionDataImportDrawerVisible"
      title="任务公式数据导入"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <a-row :gutter="16">
        <a-col :span="24">
          <FileUpload ref="taskExpressionDataImportFileUploadRef" :fileModule="taskExpressionDataImportFileModule" @change="taskExpressionDataImportFileUploadChange" />
          <a-input v-model:value="taskExpressionDataImportFileUrl" disabled addonBefore="导入文件url:" placeholder="输入导入文件url">
            <template #addonAfter>
              <a-button type="link" size="small" @click="taskExpressionDataImportFileUrlSelectFileClick">选择文件</a-button>
            </template>
          </a-input>
        </a-col>
      </a-row>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button :loading="taskExpressionDataImportSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnImportData }" @click="taskExpressionToDataImport">
            <CoreIcon :icon="coreStyle.antBtnIconImportData" :size="14" />
            导入数据
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="taskExpressionDataImportFileSelectDrawerVisible"
      title="文件选择"
      placement="right"
      :closable="false"
      destroyOnClose
      :width="'80%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 0, 0) }"
    >
      <FileSelect :fileModule="taskExpressionDataImportFileModule" @change="taskExpressionDataImportFileSelectChange" />
    </a-drawer>
    <a-drawer
      v-model:visible="taskExpressionDataExportDrawerVisible"
      title="任务公式数据导出"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <DataExportColumnSelect :optionalDataExportFieldList="taskExpressionOptionalDataExportFieldList" :selectedDataExportFieldList="taskExpressionSelectedDataExportFieldList" />
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnQueryDataExport }" @click="taskExpressionToDataExport(false)">
            <CoreIcon :icon="coreStyle.antBtnIconQueryDataExport" :size="14" />
            查询数据导出
          </a-button>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnAllDataExport }" @click="taskExpressionToDataExport(true)">
            <CoreIcon :icon="coreStyle.antBtnIconAllDataExport" :size="14" />
            全部数据导出
          </a-button>
        </a-space>
      </div>
    </a-drawer>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from 'vue-class-component'
import { mapStores } from 'pinia'
import { useCoreToolStore } from '/@/store/modules/cn/core/tool/coreToolStore'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import type { DataExportFieldAO } from '/@/model/cn/core/tool/ao/DataExportFieldAO'
import type { DataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'
import { toDataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'

import { useTaskExpressionStore } from '/@/store/modules/cn/core/kpis/taskExpressionStore'

import type { TaskExpression } from '/@/model/cn/core/kpis/eo/TaskExpression'
import { toTaskExpression } from '/@/model/cn/core/kpis/eo/TaskExpression'

import type { TaskExpressionQO } from '/@/model/cn/core/kpis/qo/TaskExpressionQO'
import { toTaskExpressionQO } from '/@/model/cn/core/kpis/qo/TaskExpressionQO'

import type { TaskExpressionVO } from '/@/model/cn/core/kpis/vo/TaskExpressionVO'
import { toTaskExpressionVO } from '/@/model/cn/core/kpis/vo/TaskExpressionVO'

@Options({
  name: 'TaskExpression',
  components: {
  },
  computed: {
    ...mapStores(useCoreToolStore, useTaskExpressionStore),
  },
})
export default class TaskExpression extends Vue {

  taskExpressionListDataSet: Array<TaskExpressionVO> = []

  taskExpressionListColumns: Array<object> = [
    {
      title: '计算公式Id',
      dataIndex: 'expressionId',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '描述',
      dataIndex: 'description',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '排序权重',
      dataIndex: 'weightOrder',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '外键Id',
      dataIndex: 'fkid',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
  ]

  taskExpressionListLoading: boolean = false

  taskExpressionListSelectedRowKeys: string[] = []

  taskExpressionListSelectData: Array<TaskExpressionVO> = []

  taskExpressionListSelectLength: number = 0

  taskExpressionListSelectCurrentRowIndex: number = -1

  taskExpressionListSelectCurrentRowData: TaskExpressionVO = toTaskExpressionVO()

  taskExpressionListPaginationVisible: boolean = true

  taskExpressionListDataPage: number = 1

  taskExpressionListDataRows: number = 10

  taskExpressionListDataCount: number = 0

  taskExpressionListRowClickTimeout: number | null = null

  taskExpressionListRowOnChange(selectedRowKeys, selectedRows) {
    this.taskExpressionListSelectedRowKeys = [ ...selectedRowKeys ]
    this.taskExpressionListSelectData = [ ...selectedRows ]
    this.taskExpressionListSelectLength = selectedRows.length
  }

  taskExpressionListCustomRow(record, index) {
    return {
      'class': index === this.taskExpressionListSelectCurrentRowIndex ? 'ant-table-row-selected' : '',
      onClick: (event) => {
        if (this.taskExpressionListRowClickTimeout) {
          clearTimeout(this.taskExpressionListRowClickTimeout)
          this.taskExpressionListRowClickTimeout = null
        } else {
          this.taskExpressionListRowClickTimeout = setTimeout(() => {
            this.taskExpressionListRowClickTimeout = null
            this.taskExpressionListSelectCurrentRowIndex = index
            this.taskExpressionListSelectCurrentRowData = { ...record }
            let selectedRowKeys = [ ...this.taskExpressionListSelectedRowKeys ]
            let selectedRows = [ ...this.taskExpressionListSelectData ]
            if (selectedRowKeys.includes(record.id)) {
              this.taskExpressionListRowOnChange([ ...selectedRowKeys.filter(eo => { return eo !== record.id }) ], [ ...selectedRows.filter(eo => { return eo.id !== record.id }) ])
            } else {
              selectedRowKeys.push(record.id)
              selectedRows.push(record)
              this.taskExpressionListRowOnChange([ ...new Set(selectedRowKeys) ], [ ...new Set(selectedRows) ])
            }
          }, 200)
        }
      },
      onDblclick: (event) => {
        this.taskExpressionStore.pkVo(this.$toParam<TaskExpressionQO>({ id: record.id } as TaskExpressionQO)).then((res: Res<TaskExpressionVO>) => {
          if (res.succ) {
            this.taskExpressionDetailModel = { ...res.data[0] }
            this.taskExpressionDetailDrawerVisible = true
          } else {
            this.$message.error(res.msg, 6)
          }
        })
      },
    }
  }

  taskExpressionListGetDataSet() {
    this.taskExpressionListLoading = true
    this.taskExpressionListRowOnChange([], [])
    this.taskExpressionListSelectCurrentRowIndex = -1
    this.taskExpressionListSelectCurrentRowData = toTaskExpressionVO()
    this.taskExpressionStore.pagingVo(this.$toParam<TaskExpressionQO>({ weightOrderAsc: 'y' } as TaskExpressionQO, this.taskExpressionListDataPage, this.taskExpressionListDataRows)).then((res: Res<TaskExpressionVO>) => {
      if (res.succ) {
        this.taskExpressionListPaginationVisible = true
        this.taskExpressionListDataSet = [ ...res.data ]
        this.taskExpressionListDataCount = res.count
        setTimeout(() => { this.taskExpressionListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.taskExpressionListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.taskExpressionListLoading = false }, 500)
    })
  }

  taskExpressionListPaginationChange() {
    this.taskExpressionListGetDataSet()
  }

  taskExpressionListPaginationShowSizeChange() {
    this.taskExpressionListGetDataSet()
  }

  taskExpressionFormQueryVisible: boolean = false

  taskExpressionFormQuerySubmitting: boolean = false

  taskExpressionFormQueryModel: TaskExpressionQO = toTaskExpressionQO()

  taskExpressionFormQueryUpDown() {
    this.taskExpressionFormQueryVisible = !this.taskExpressionFormQueryVisible
  }

  taskExpressionFormQueryReset() {
    if (this.$refs.taskExpressionFormQueryRef) {
      this.$refs.taskExpressionFormQueryRef.resetFields()
      this.taskExpressionFormQueryModel = toTaskExpressionQO()
    }
  }

  taskExpressionFormQuerySearch() {
    this.taskExpressionFormQuerySubmitting = true
    this.taskExpressionListLoading = true
    this.taskExpressionListRowOnChange([], [])
    this.taskExpressionListSelectCurrentRowIndex = -1
    this.taskExpressionListSelectCurrentRowData = toTaskExpressionVO()
    this.taskExpressionStore.queryVo(this.$toParam<TaskExpressionQO>(this.$toSearch({ ...this.taskExpressionFormQueryModel }))).then((res: Res<TaskExpressionVO>) => {
      if (res.succ) {
        this.taskExpressionListPaginationVisible = false
        this.taskExpressionListDataSet = [ ...res.data ]
        this.taskExpressionListDataCount = res.count
        setTimeout(() => { this.taskExpressionFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.taskExpressionListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.taskExpressionFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.taskExpressionListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.taskExpressionFormQuerySubmitting = false }, 5000)
      setTimeout(() => { this.taskExpressionListLoading = false }, 500)
    })
  }

  taskExpressionEditDrawerVisible: boolean = false

  taskExpressionFormSaveSubmitting: boolean = false

  taskExpressionFormSaveContinue: boolean = false

  taskExpressionFormModel: TaskExpression = toTaskExpression()

  taskExpressionFormRules: object = {
    // expressionId: [
    //   { type: 'string', required: true, message: '计算公式Id不能为空！', trigger: ['change', 'blur'] },
    // ],
    // description: [
    //   { type: 'string', required: true, message: '描述不能为空！', trigger: ['change', 'blur'] },
    // ],
    // weightOrder: [
    //   { type: 'number', required: true, message: '排序权重不能为空！', trigger: ['change', 'blur'] },
    // ],
    // fkid: [
    //   { type: 'string', required: true, message: '外键Id不能为空！', trigger: ['change', 'blur'] },
    // ],
  }

  taskExpressionFormReset() {
    if (this.$refs.taskExpressionFormRef) {
      this.$refs.taskExpressionFormRef.resetFields()
      this.taskExpressionFormModel = toTaskExpression()
    }
  }

  taskExpressionFormSubmit() {
    this.taskExpressionFormSaveSubmitting = true
    this.$refs.taskExpressionFormRef.validate().then(() => {
      if (this.taskExpressionFormModel.id) {
        this.taskExpressionStore.update(this.$toParam<TaskExpression>(this.taskExpressionFormModel)).then((res: Res<TaskExpression>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.taskExpressionFormReset()
            this.taskExpressionFormSaveSubmitting = false
            if (!this.taskExpressionFormSaveContinue) {
              this.taskExpressionEditDrawerVisible = false
              this.taskExpressionListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.taskExpressionFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.taskExpressionFormSaveSubmitting = false }, 3000)
        })
      } else {
        this.taskExpressionStore.save(this.$toParam<TaskExpression>(this.taskExpressionFormModel)).then((res: Res<TaskExpression>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.taskExpressionFormReset()
            this.taskExpressionFormSaveSubmitting = false
            if (!this.taskExpressionFormSaveContinue) {
              this.taskExpressionEditDrawerVisible = false
              this.taskExpressionListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.taskExpressionFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.taskExpressionFormSaveSubmitting = false }, 3000)
        })
      }
    }).catch(() => {
      setTimeout(() => { this.taskExpressionFormSaveSubmitting = false }, 3000)
    })
  }

  taskExpressionFormSave() {
    this.taskExpressionFormSaveContinue = false
    this.taskExpressionFormSubmit()
  }

  taskExpressionFormNextAdd() {
    this.taskExpressionFormSaveContinue = true
    this.taskExpressionFormSubmit()
  }

  taskExpressionAdd() {
    if (this.taskExpressionFormModel.id) {
      this.taskExpressionFormReset()
    }
    this.taskExpressionEditDrawerVisible = true
  }

  taskExpressionUpdate() {
    this.taskExpressionStore.pk(this.$toParam<TaskExpressionQO>({ id: this.taskExpressionListSelectData[0].id } as TaskExpressionQO)).then((res: Res<TaskExpression>) => {
      if (res.succ) {
        this.taskExpressionFormReset()
        this.taskExpressionFormModel = { ...res.data[0] }
        this.taskExpressionEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskExpressionEditDrawerOnClose() {
    if (this.taskExpressionFormSaveContinue) {
      this.taskExpressionFormSaveContinue = false
      this.taskExpressionListGetDataSet()
    }
  }

  taskExpressionDelete() {
    let param: Array<TaskExpression> = []
    this.taskExpressionListSelectData.forEach((eo: TaskExpressionVO) => {
      param.push({ id: eo.id } as TaskExpression)
    })
    this.taskExpressionStore.removeBatch(this.$toParam<TaskExpression>(param)).then((res: Res<TaskExpression>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.taskExpressionListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskExpressionDetailDrawerVisible: boolean = false

  taskExpressionDetailModel: TaskExpressionVO = toTaskExpressionVO()

  taskExpressionDetailInfo() {
    this.taskExpressionStore.pkVo(this.$toParam<TaskExpressionQO>({ id: this.taskExpressionListSelectData[0].id } as TaskExpressionQO)).then((res: Res<TaskExpressionVO>) => {
      if (res.succ) {
        this.taskExpressionDetailModel = { ...res.data[0] }
        this.taskExpressionDetailDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskExpressionDetailUpdate() {
    this.taskExpressionStore.pk(this.$toParam<TaskExpressionQO>({ id: this.taskExpressionDetailModel.id } as TaskExpressionQO)).then((res: Res<TaskExpression>) => {
      if (res.succ) {
        this.taskExpressionFormReset()
        this.taskExpressionFormModel = { ...res.data[0] }
        this.taskExpressionDetailDrawerVisible = false
        this.taskExpressionEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskExpressionTemplateDownload() {
    this.coreToolStore.getValueByConfKey('defaultDataImportTemplate').then((res: string) => {
      window.open(this.coreToolStore.getFileFullUrl(res), '_blank')
    })
  }

  taskExpressionDataImportDrawerVisible: boolean = false

  taskExpressionDataImportFileSelectDrawerVisible: boolean = false

  taskExpressionDataImportFileModule: string = 'dataImport'

  taskExpressionDataImportFileUrl: string = ''

  taskExpressionDataImportSaveSubmitting: boolean = false

  taskExpressionDataImport() {
    this.taskExpressionDataImportDrawerVisible = true
  }

  taskExpressionDataImportFileUploadChange(value) {
    this.taskExpressionDataImportFileUrl = value
  }

  taskExpressionDataImportFileUrlSelectFileClick() {
    this.taskExpressionDataImportFileSelectDrawerVisible = true
  }

  taskExpressionDataImportFileSelectChange(fileUrl) {
    this.taskExpressionDataImportFileUrl = fileUrl
    this.taskExpressionDataImportFileSelectDrawerVisible = false
  }

  taskExpressionToDataImport() {
    this.taskExpressionDataImportSaveSubmitting = true
    this.taskExpressionStore.dataImport(this.$toParam<string>(this.taskExpressionDataImportFileUrl)).then((res: Res<TaskExpression>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.$refs.taskExpressionDataImportFileUploadRef.resetFiles()
        this.taskExpressionDataImportFileUrl = ''
        this.taskExpressionDataImportSaveSubmitting = false
        this.taskExpressionDataImportDrawerVisible = false
        this.taskExpressionListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.taskExpressionDataImportSaveSubmitting = false }, 3000)
      }
    }).catch(err => {
      setTimeout(() => { this.taskExpressionDataImportSaveSubmitting = false }, 3000)
    })
  }

  taskExpressionDataExportDrawerVisible: boolean = false

  taskExpressionOptionalDataExportFieldList: Array<DataExportFieldAO> = [
    {
      fieldName: 'expressionId',
      fieldComment: '计算公式Id',
    },
    {
      fieldName: 'description',
      fieldComment: '描述',
    },
    {
      fieldName: 'weightOrder',
      fieldComment: '排序权重',
    },
    {
      fieldName: 'fkid',
      fieldComment: '外键Id',
    },
  ]

  taskExpressionSelectedDataExportFieldList: Array<DataExportFieldAO> = []

  taskExpressionDataExport() {
    this.taskExpressionDataExportDrawerVisible = true
  }

  taskExpressionToDataExport(allData: boolean) {
    this.taskExpressionStore.dataExport(this.$toParam<DataExportAO<TaskExpressionQO>>(toDataExportAO(this.taskExpressionSelectedDataExportFieldList, allData ? { weightOrderAsc: 'y' } as TaskExpressionQO : this.$toSearch({ ...this.taskExpressionFormQueryModel }), '任务公式信息数据导出.xlsx'))).then((res: Res<string>) => {
      if (res.succ) {
        window.open(this.coreToolStore.getFileFullUrl(res.data[0]), '_blank')
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  mounted() {
    // this.taskExpressionFormQueryModel.weightOrderAsc = 'y'
    this.taskExpressionListGetDataSet()
  }

}
</script>

<style scoped lang="less">

</style>
